<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>首页</h1>
<div>
    <h2>{{info}}</h2>
    <input type="button" VALUE="get请求" @click="f1()">
    <input type="button" VALUE="post请求" @click="f2()">
</div>


<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script>
    let v = new Vue({
        el: "div", data: {
            info: "Vue测试"
        },
        methods: {
            f1: function () {
                //发出异步的get请求
                axios.get("/helloAxios?name=tom").then(function (response) {
                    // alert("接收到了服务器的响应:" + response.data);
                    v.info = response.data;
                }).catch(function (err) {
                    alert(err);
                })
            },
            f2: function () {
                let data = new FormData();
                data.append("name","jerry")

                //发出异步的post请求
                axios.post("/helloAxios",data).then(function (response) {
                    alert("接收到了服务器的响应:" + response.data);
                })

            }
        }
    })
</script>
</body>
</html>